
//
//   AdvancedOperatorsViewController.swift
//  SwiftTest
//
//  Created by midea on 16/3/21.
//  Copyright © 2016年 Vincent. All rights reserved.
//

import Foundation
import UIKit

class  AdvancedOperatorsViewController : BaseViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.titles = ["opposite","and","bitwiseOr"]
        self.tableView?.reloadData()
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        super.tableView(tableView, didSelectRowAt: indexPath)
        
        switch indexPath.row{
        case 0:
            opposite()
        case 1:
            and()
        case 2:
            bitwiseOr()
        default:
            print("no more methods")
        }
    }
    
    fileprivate func opposite(){
        let initialBits: UInt8 = 0b00001111
        let invertedBits = ~initialBits  // 等于 0b11110000
        print(invertedBits)
    }
    
    fileprivate func and(){
        let firstSixBits: UInt8 = 0b11111100
        let lastSixBits: UInt8  = 0b00111111
        let middleFourBits = firstSixBits & lastSixBits  // 等于 00111100
        print(middleFourBits)
    }
    
    fileprivate func bitwiseOr(){
        let someBits: UInt8 = 0b10110010
        let moreBits: UInt8 = 0b01011110
        let combinedbits = someBits | moreBits  // 等于 11111110
        print(combinedbits)
    }
}
